
import { GStatic } from "../../../Core/Manager/DataPool";
import GameMgr from "../../Logic/GameMgr";

const { ccclass } = cc._decorator;
@ccclass
export class SSuitData extends GStatic {
    public parse(obj: any): boolean {
        for (let i = 0; i < obj.data.length; i++) {
            let raw = GStatic.addonRaw<SSuitDataRaw>(obj.data[i]);
            this._data.set(raw.id, raw);
        }
        return true;
    }

    /**获取英雄可以使用的所有套装 */
    public getAllHeroSuit(id: number) {
        var heroArr = [];
        this._data.forEach((v: SSuitDataRaw) => {
            v.hero.forEach((s: number) => {
                if (s == id) {
                    heroArr.push(v.id);
                }
            })
        })
        return heroArr
    }

    /**获取有该装备或者兵书的唯一套装 */
    public getHeroSuit(id, arr) {
        let suitArr: SSuitDataRaw;
        arr.forEach((value) => {
            let suit = GameMgr.suitData.getRaw<SSuitDataRaw>(value).suit;
            suit.forEach((s) => {
                if (s == id) {
                    suitArr = GameMgr.suitData.getRaw<SSuitDataRaw>(value);
                }
            })
        })
        return suitArr
    }
}